<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>LingPowerAI</title>
		<script type="text/javascript">
			document.write('<script src="../../js/fix.js?rd=?rd=' + Math.random() + '"><\/script>');
		</script>
		<script type="text/javascript">
			link(['../../css/reset.css']);
		</script>
		<style type="text/css">
			.loginformwarp form span {
				color: darkgray;
			}
			input[type="text"],input[type="password"]{
				font-size: 0.15rem;
			}
			
		</style>
	</head>

	<body class="bg-lan-default" style="display: none;">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">找回密码</h1>
		</header>
		<div class="mui-content mui-scroll-wrapper scroll">
			<div class="mui-scroll">
				<div class="loginformwarp">
					<div class="m1rem">
						<form class="mui-input-group">
							<div class="input-group">
								<div class="mui-input-row">
									<span class="mui-icon fa fa-tablet"></span>
									<input id='inpt_mobile' type="text" class="mui-input-clear mui-input" maxlength="11" placeholder="请输入手机号">
								</div>
								<div class="mui-input-row clearr100">
									<span class="mui-icon fa fa-shield"></span>
									<input id='inpt_validcode' type="text" class="mui-input-clear mui-input" maxlength="6" placeholder="请输入手机验证码">
									<button id="btn_sendvalidcode" class="btn-rightwarp">获取验证码</button>
								</div>
								<div class="mui-input-row">
									<span class="mui-icon fa fa-lock"></span>
									<input id='inpt_new_password' type="password" class="mui-input-clear mui-input" maxlength="11" placeholder="请输入新密码">
								</div>
							</div>
						</form>
						<div>
							<button class="mui-btn mui-btn-block btn-ok" id='btn_next'>确定</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			//必须顺序加载
			script();
		</script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				storage.init();
				var btn_sendvalidcode = document.getElementById("btn_sendvalidcode");
				var btn_next = document.getElementById("btn_next");
				var inpt_mobile = document.getElementById("inpt_mobile");
				var inpt_validcode = document.getElementById("inpt_validcode");
				var inpt_new_password = document.getElementById("inpt_new_password");

				storageUser = kidstorageuser.getInstance();
				inpt_mobile.value = storageUser.UserName;

				if (ismobileno(inpt_mobile.value)) {
					appUI.removeDisabled(btn_sendvalidcode);
				}

				//发送验证码
				btn_sendvalidcode.addEventListener("tap", function() {
					if(inpt_mobile.value.trim() == "") {
					appUI.showTopTip("请输入手机号");
					//mui.toast("请输入手机号");
					inpt_mobile.focus();
				} else if(!ismobileno(inpt_mobile.value)) {
					appUI.showTopTip("手机号格式不正确");
					//mui.toast("手机号格式不正确");
				} else {
					appUI.setDisabled(btn_sendvalidcode);
					request("/cmdb/send_sms/", {
						tel_no: inpt_mobile.value,
						type: 'SMS1001'
					}, function(json) {
						inpt_validcode.setAttribute("vcode",json.DATASET[0].sms_code)
						inpt_validcode.setAttribute("vphone",json.DATASET[0].phone)
						mui.toast(json.ERROR_MESSAGE);
						appUI.removeDisabled(btn_sendvalidcode);
						if(json[SysConstants.ERROR_CODE_KEY] == SysConstants.ERROR_CODE_OBJECT.ERROR_CODE_SUCCESS) {
							time(btn_sendvalidcode);
						}
					});
				}
				});

				//下一步
				btn_next.addEventListener("tap", function() {
					if (inpt_mobile.value.trim() == "") {
						appUI.showTopTip("请输入手机号");
						//mui.toast("请输入手机号");
						//inpt_mobile.focus();
					} else if (!ismobileno(inpt_mobile.value)) {
						appUI.showTopTip("手机号格式不正确");
						//mui.toast("手机号格式不正确");
					} else if (inpt_validcode.value.trim() == "") {
						appUI.showTopTip("请输入验证码");
						//mui.toast("请输入验证码");
						//inpt_pwd.focus();
					}else if(inpt_validcode.value!=inpt_validcode.getAttribute("vcode") || inpt_mobile.value!=inpt_validcode.getAttribute("vphone")) {
					  	appUI.showTopTip("验证码错误");
					  	//mui.toast("请输入验证码");
					  	//inpt_pwd.focus();
					  } else {
						appUI.setDisabled(btn_next);
						request("/cmdb/updateSalesPWD/", {
							tel_no: inpt_mobile.value,
							new_pwd: inpt_new_password.value
						}, function(json) {
							appUI.removeDisabled(btn_next);
							if (json[SysConstants.ERROR_CODE_KEY] == SysConstants.ERROR_CODE_OBJECT.ERROR_CODE_SUCCESS) {
								var data = json[SysConstants.DATASET_KEY];
								log(data);
								mui.toast("密码修改成功");
								
								openNew("login.html", {
									mobile: inpt_mobile.value,
									type: "findpwd"
								});
								setTimeout(function(){
									inpt_validcode.value="";
									inpt_new_password.value="";
								},1000);
								
							} else {
								appUI.showTopTip(json[SysConstants.ERROR_MESSAGE_KEY]);
								//mui.toast(json[SysConstants.ERROR_MESSAGE_KEY]);
							}
						});
					}
				});
			})
		</script>
	</body>
</html>
